<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="iconfont icon-remove_circle_outline" v-if="food.count" @click.stop="updateFoodCount(false)"></div>
    </transition>
    <div class="cart-count" v-if="food.count">{{food.count}}</div>
    <div class="iconfont icon-add_circle" @click.stop="updateFoodCount(true)"></div>
  </div>
</template>

<script>
  export default {
    name: 'CartControl',
    props: {
      food: Object,
    },
    methods: {
      updateFoodCount(isAdd) {
        this.$store.dispatch('updateFoodCount', {isAdd, food: this.food})
      },
    },
  }
</script>

<style lang="less">
  @import '../../common/less/mixins.less';
  .cartcontrol {
    font-size: 0;
    .cart-decrease {
      display: inline-block;
      padding: 6px;
      line-height: 24px;
      font-size: 24px;
      color: rgba(0, 160, 220, 1);
    }
    .icon-remove_circle_outline {
      display: inline-block;
      padding: 6px;
      line-height: 24px;
      font-size: 24px;
      color: @green;
      // 显示时样式
      &.move-enter-active,
      &.move-leave-active {
        transition: all .3s;
      }
      // 隐藏时样式
      &.move-enter,
      &.move-leave-to {
        opacity: 0;
        transform: translateX(15px) rotate(189deg);
      }
    }
    .cart-count {
      display: inline-block;
      width: 12px;
      padding-top: 6px;
      line-height: 24px;
      font-size: 10px;
      vertical-align: top;
      text-align: center;
      color: rgba(147, 153, 159, 1);
    }
    .icon-add_circle {
      display: inline-block;
      padding: 6px;
      line-height: 24px;
      font-size: 24px;
      color: @green;
    }
  }
  
</style>
